package com.omi.iberolactalpreventa;

import java.util.ArrayList;

import com.omi.iberolactalpreventa.objects.AdapterCommentPredef;
import com.omi.iberolactalpreventa.objects.ItmCommentPredef;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;

import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;


public class CommentPref extends Activity 
{
	
private ListView lstcompref;

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_comments_predef);

	lstcompref =  (ListView)findViewById(R.id.lstcompredef);
	
	Cursor c = Modulebase.db.ejecutarSelect(new String[]{"Comentario"}, "Coment_Pred", null, null);
	
	if(c!=null && c.moveToFirst())
	{
	ArrayList<ItmCommentPredef> items = new ArrayList<ItmCommentPredef>();
	//Rellenamos la lista:
	do
	{
		ItmCommentPredef itm = new ItmCommentPredef(c.getString(0));
		items.add(itm);
	}while(c.moveToNext());
	
	AdapterCommentPredef adpt = new AdapterCommentPredef(this, items);

	lstcompref.setAdapter(adpt);
	}
	
	//EVENTO al hacer click que seleccione el comentario:
	lstcompref.setOnItemClickListener(new OnItemClickListener() {

		@SuppressLint("NewApi")
		@Override
		public void onItemClick(AdapterView<?> parent, View v, int position,long id) {
			ItmCommentPredef aux = (ItmCommentPredef) parent.getItemAtPosition(position);
			Modulebase.commentTemp = aux.getComment();
			finish();
		}
	});
	
	getActionBar().setDisplayHomeAsUpEnabled(true);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
         finish();
        default: 
         return super.onOptionsItemSelected(item);      
        }
}


@Override
public void onBackPressed() {
	finish();
}


}
